home *** CD-ROM | disk | FTP | other *** search
- // This example CGI program shows how to use C and C++ programs with the
- // Savant web server to create dynamically generated content.
-
- // For more information about Savant, visit
- // http://savant.sourceforge.net
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <iostream.h>
-
- void main()
- {
- char query[128];
-
- //Read in query string
- cin >> query;
-
- //Output HTTP header info
- cout << "Content-type: text/html\n\n";
-
- //Output HTML page
- cout << "<html>" << endl;
- cout << "<head>" << endl;
- cout << "<title>CGI Test</title>" << endl;
- cout << "</head>" << endl;
- cout << "<body>" << endl;
- cout << "<center><b><font face=\"Arial,Helvetica\"><font color=\"#0000FF\"><font size=+4>" << endl;
- cout << "CGI Test Results</font></font></font></b></center>" << endl;
- cout << "<p><br><br>" << endl;
- cout << "<p><font face=\"Arial,Helvetica\">Results from the HTML form:</font>" << endl;
- cout << "<p><font face=\"Arial,Helvetica\">Color:</font>" << endl;
- cout << "<table BORDER CELLSPACING=0 WIDTH=\"50\" HEIGHT=\"25\" >" << endl;
- cout << "<tr><td BGCOLOR=" << endl;
-
- //Output the appropriate color code based on what the user selected in the
- //HTML form
- if (strstr(query, "red"))
- cout << "\"#FF0000\"";
- if (strstr(query, "green"))
- cout << "\"#00FF00\"";
- if (strstr(query, "blue"))
- cout << "\"#0000FF\"";
-
- cout << "> </td></tr>" << endl;
- cout << "</table><p>" << endl;
-
- //Print out some of the more useful CGI environment variables. You can use
- //these in your programs for a variety of reasons.
- cout << "CONTENT_LENGTH (length of query string): " << getenv("CONTENT_LENGTH") << "<br>" << endl;
- cout << "SERVER_SOFTWARE : " << getenv("SERVER_SOFTWARE") << "<br>" << endl;
- cout << "SERVER_NAME : " << getenv("SERVER_NAME") << "<br>" << endl;
- cout << "SERVER_PROTOCOL : " << getenv("SERVER_PROTOCOL") << "<br>" << endl;
- cout << "SERVER_PORT : " << getenv("SERVER_PORT") << "<br>" << endl;
- cout << "REMOTE_HOST : " << getenv("REMOTE_HOST") << "<br>" << endl;
- cout << "REMOTE_ADDR : " << getenv("REMOTE_ADDR") << "<br>" << endl;
- cout << "HTTP_USER_AGENT : " << getenv("HTTP_USER_AGENT") << "<br>" << endl;
- cout << "HTTP_REFERER : " << getenv("HTTP_REFERER") << "<br>" << endl;
- cout << "</body></html>" << endl;
-
- }
-